package com.vtech.ws.cxf.config;

import com.vtech.ws.cxf.service.InfoService;
import org.apache.cxf.Bus;
import org.apache.cxf.ext.logging.LoggingFeature;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.ws.Endpoint;

/**
 * TODO
 * soap webservice configure
 *
 * @author houzhiwei
 * @date 2018/7/22 16:39
 */
@Configuration
public class CXFConfiguration {

    @Autowired
    private Bus bus;

   /*
   @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }
    */

    @Autowired
    private InfoService infoService;


    //    soap web service

    @Bean
    public Endpoint endpoint() {
        EndpointImpl endpoint = new EndpointImpl(bus, infoService);
        // services/info
        endpoint.getFeatures().add(new LoggingFeature());
        endpoint.publish("/info");
        return endpoint;
    }


    /*@Bean
    public AnotherService anotherService() {
        return new AnotherServiceImpl();
    }

    @Bean
    public Endpoint anotherEndpoint(AnotherService anotherService) {
        EndpointImpl endpoint = new EndpointImpl(springBus(), anotherService);
        endpoint.publish("/another");
        return endpoint;
    }*/

    //    restful web service

    /*@Autowired
    private CxfRsService rsService;
    @Bean
    public Server rsServer() {
        final JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
        endpoint.setProvider(new JacksonJsonProvider());
//        endpoint.setBus(bus);
        endpoint.setAddress("/rs");
//        endpoint.setServiceBeans(Arrays.<Object>asList());
        endpoint.setServiceBean(rsService);
        endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
        return endpoint.create();
    }
    public OpenApiFeature createOpenApiFeature() {
        OpenApiFeature openApiFeature = new OpenApiFeature();
        openApiFeature.setPrettyPrint(true);
        OpenApiCustomizer customizer = new OpenApiCustomizer();
        customizer.setDynamicBasePath(true);
        openApiFeature.setCustomizer(customizer);
        openApiFeature.setTitle("Spring Boot CXF REST Application");
        openApiFeature.setContactName("The Apache CXF team");
        openApiFeature.setDescription("This sample project demonstrates how to use CXF JAX-RS services"
                                              + " with Spring Boot. This demo has two JAX-RS class resources being"
                                              + " deployed in a single JAX-RS endpoint.");
        openApiFeature.setVersion("1.0.0");
        return openApiFeature;
    }*/
}
